package com.usian.controller;

import com.usian.pojo.User;
import com.usian.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @RequestMapping("/tologin")
    public String tologin(){
        return "login";
    }
    @RequestMapping("/toadd")
    public String toadd(){
        return "insert";
    }

    @RequestMapping("/add")
    public String add(User user){
        roleService.add(user);
        return "redirect:tologin";
    }



    @RequestMapping("/login")
    public String login(User user){
       User num = roleService.findUser(user);
        System.out.println(num);
       if (num==null){
           return "login";
       }
        /*if(user.getName() == null || user.getPwd() == null || !user.getPwd().getValue().equals(this.password)) {
            //登陆失败
            this.msg = "用户不存在或密码错误！";
            return Action.INPUT;
        } else {
            //登陆成功
            //设置session
            this.getSession().setAttribute("_USER_INFO_LOGIN_NAME_", this.loginname);
            this.getSession().setAttribute("_USER_INFO_USER_ID_", user.getId().getValue());
            this.getSession().setAttribute("_USER_INFO_USER_INFO_", user);
            //设置cookie
            this.getResponse().addCookie(new Cookie("_USER_INFO_LOGIN_NAME_", this.loginname));
            this.getResponse().addCookie(new Cookie("_USER_INFO_USER_ID_", user.getId().getValue()));
            return Action.SUCCESS;
        }*/
        Integer aid = num.getAid();
        System.out.println(aid);
       if(aid==1){
           return "redirect:/user/caozuo";
       }else {
           return "redirect:/user/findList";
       }
    }
}
